<template>
  <div>
    <div>
      <el-card>
        <div class="clearfix">
          <span>角色管理</span>
        </div>

        <div class="set">
          <el-button size="big" type="primary" @click="dialogVisible = true"
            >添加</el-button
          >
        </div>

        <el-table
          size="mini"
          @selection-change="handleSelectionChange"
          :data="getrole"
          border
          style="width: 100%"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column prop="id" label="id" width="110"></el-table-column>
          <el-table-column
            prop="name"
            label="登录账号"
            width="110"
          ></el-table-column>
          <el-table-column label="操作" width="180px">
            <template slot-scope="scoped">
              <el-button size="big" type="success">修改</el-button>
              <el-button type="danger"  @click="open(scoped.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page"
          :page-sizes="[4, 10, 15, 20]"
          :page-size="page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </el-card>
    </div>

    <!-- 点击添加后打开的东西 -->
    <el-dialog
      title="添加角色"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <div class="center">
        <el-form ref="form" :model="form" label-width="40px">
          <el-form-item label="账号">
            <el-input v-model="form.name"></el-input>
          </el-form-item>

          <el-form-item label="角色">
            <el-checkbox-group v-model="form.type">
              <el-checkbox label="生活缴费" name="type"></el-checkbox><br />
              <el-checkbox label="查看费用" name="type"></el-checkbox>
              <el-checkbox label="删除费用" name="type"></el-checkbox>
              <el-checkbox label="添加楼栋" name="type"></el-checkbox><br />
              <el-checkbox label="楼栋管理" name="type"></el-checkbox>
              <el-checkbox label="添加楼栋" name="type"></el-checkbox>
              <el-checkbox label="修改楼栋" name="type"></el-checkbox>
              <el-checkbox label="查看楼栋信息" name="type"></el-checkbox>
              <el-checkbox label="删除楼栋" name="type"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-form>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getrole, getroledeldte } from "../../api/user.js";
export default {
  data() {
    return {
      page: 1,
      pageSize: 5,
      total: 1, //分页
      getrole: [],
      getroledeldte:[],
      form: {
         type: [],
      },
      query: {},
      total:0,
      multipleSelection: [],
      dialogVisible: false,
    };
  },
  methods: {
    //分页
    handleSizeChange(val){
      this.pageSize=val;
      this.getroles();
    },
    handleCurrentChange(val){
      this.page=val;
      this.getroles();
    },

    onSubmit() {
      console.log("submit!");
    },
    //角色数据渲染  分页内容
    async getroles() {
      const res = await getrole({
        page:this.page,
        psize:this.pageSize
      });
      console.log('2222',res);
      this.getrole = res.data.list;
      this.total=res.data.counts;
      // console.log(res);
    },
    //单选删除
      open(id) {
      console.log(id);
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      }).then(() => {
        getroledeldte({ id: id }).then((res) => {
          console.log(res);
          this.getroles();
          if (res.errCode == 10000) {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            // this.getinmatelists();
          }
        });
      });
    },
  },
 
  created() {
    this.getroles();
  },
};
</script>

<style lang="less" scoped>
.el-row {
  border-bottom: 1px solid #eee;
  height: 70px;
  line-height: 70px;
}
.clearfix {
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}
.clearfix span {
  color: blue;
}
.el-input {
  width: 30%;
  height: 30px;
  font-size: 12px;
}

.el-select {
  width: 35%;
  height: 30px;
  font-size: 12px;
}
.set {
  margin-top: 20px;
}
.el-table {
  font-size: 12px;
  margin: 10px 0px;
}
.el-breadcrumb {
  margin: 10px 0px;
}
.addright {
  float: right;
}
.el-tag {
  margin: 15px 10px;
}
.el-col-7 {
  width: 27%;
}
.el-table[data-v-09d83b62] {
  font-size: 18px;
  margin: 10px 0px;
}
.center {
  width: 100%;
  height: 400px;
  // background-color: red;
}
.left {
  width: 50%;
  // height: 20px;
  float: left;
  // background-color: pink;
}
.right {
  width: 50%;
  // height: 20px;
  float: right;
  // background-color: rgb(17, 15, 15);
}
</style>
